
var url = location.search; //获取url中"?"符后的字串 ('?modFlag=business&role=1')
console.log(url);
var sp=url.split("?");
var a=location.search.split("=")[1];
console.log(a);

$(document).ready(function () {

        $.ajax({
                type: 'post',
                url:"http://39.108.233.68:8080/selRouteById" ,
                data: {
                    id: a,
                },
                datatype:'json',
                success: function (data) {
                    var data1=JSON.stringify(data);
                    console.log(data1);
                    // alert("success");

                    $("#change_id").val(data.data.routeMes.id);

                    $("#change_length").val(data.data.routeMes.length);
                    $("#change_startplace").val(data.data.startCity)
                    $("#change_endplace").val(data.data.endCity);
                    $("#change_days").val(data.data.routeMes.days);
                    $("#change_describetion").val(data.data.routeMes.describetion);
                    $("#change_entryfee").val(data.data.routeMes.entryfee);
                    $("#change_type").val(data.data.routeMes.type);
                    // document.getElementById('change_id').innerText="data.data.routeMes.id";

                },
                error: function () {
                    alert("error");
                }
            }
        )
    }
)

function foundcityid(city){
    var cityid;
    $.ajax({
        type: 'post',
        url:"http://39.108.233.68:8080/selSomeCity",
        async:false,
        data: {
            key:city

        },
        datatype:'json',
        success: function (data) {

            data1=JSON.stringify(data)
            console.log(data1);

            for (i in data.data)
            {
                cityid=data.data[i].id;
                // console.log(cityid);
            }
            // console.log(cityid);

        },
        error: function () {
            alert("error");
        }
    })
    console.log(cityid);
    return cityid;
}
$(function () {
    $("#change_submit").click(function () {

        var id = document.getElementById("change_id").value;
        var length = document.getElementById("change_length").value;
        var startplace = document.getElementById("change_startplace").value;
        var endplace = document.getElementById("change_endplace").value;
        var    startpalceid=foundcityid(startplace);
        if(startpalceid==null)
        {
            alert("无此起点城市")
        }
        var   endplaceid=foundcityid(endplace);
        if(endplaceid==null)
        {
            alert("无此终点城市")
        }

        var days = document.getElementById("change_days").value;
        var describetion = document.getElementById("change_describetion").value;
        var entryfee = document.getElementById("change_entryfee").value;
        var type = document.getElementById("change_type").value;
        var routemeslist=[];
        var routemes= new Object();

        routemes.describetion=describetion;//经过城市

        routemeslist.push(routemes);

        if(change_id!= ""&& change_length!="" &&change_startplace!=''&& change_endplace!=""&& change_days!=""&& change_describetion!=""&& change_entryfee!="") {

            $.ajax({
                    type: 'post',
                    url:"http://39.108.233.68:8080/updOneRoute" ,
                    data: {
                        id:id,
                        length:length,
                        days:days,
                        startplaceid:startpalceid,
                        endplaceid:endplaceid,
                        describetion:describetion,
                        entryfee:entryfee,
                        type:type,
                        // cityMesList:JSON.stringify(routemeslist),

                    },

                    success: function (data) {

                        alert("修改成功！");
                    },
                    error: function () {
                        alert("error");
                    }
                }
            )
        }


        else {
            alert("所有内容均不能为空！")
        }
    })
})
